/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package toybox.behavioral.chainofresponsibility;

/**
 *
 * @author BuccatR
 */
public class ChainOfResponsibility {

    public static void main(String[] args) {

        Logger l,l1;

        l1 = l = new StdoutLogger(Logger.DEBUG);
        l1 = l1.setNext(new EmailLogger(Logger.NOTICE));
        l1 = l1.setNext(new StderrLogger(Logger.ERR));


        l.message("X", Logger.DEBUG);
        l.message("Y", Logger.NOTICE);
        l.message("Z", Logger.ERR);
        
    }

}

class StdoutLogger extends Logger {
    public StdoutLogger(int mask) {
        this.mask = mask;
    }
    protected void writeMessage(String msg) {
        System.out.println("[STDOUT]" + msg);
    }
}

class EmailLogger extends Logger {
    public EmailLogger(int mask) {
        this.mask = mask;
    }
    protected void writeMessage(String msg) {
        System.out.println("[EMAIL]" + msg);
    }
}

class StderrLogger extends Logger {
    public StderrLogger(int mask) {
        this.mask = mask;
    }
    protected void writeMessage(String msg) {
        System.err.println("[ERR]" + msg);
    }
}